package smartclass.slidingmenu.example;

import smartclass.entity.StudentInfo;

import com.jeremyfeinstein.slidingmenu.example.R;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SampleListFragment extends ListFragment {

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.list, null);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		StudentAdapter adapter = new StudentAdapter(getActivity());
		setListAdapter(adapter);
		StudentInfo student = new StudentInfo();
		student.setName("Tran Van Thang");
		student.setGender("male");
		adapter.add(student);
		StudentInfo student1 = new StudentInfo();
		student1.setName("Bui Thi Hong Dieu");
		student1.setGender("female");
		adapter.add(student1);
	}

	public class StudentAdapter extends ArrayAdapter<StudentInfo> {

		public StudentAdapter(Context context) {
			super(context, 0);
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(getContext()).inflate(
						R.layout.row, null);
			}
			ImageView icon = (ImageView) convertView
					.findViewById(R.id.row_icon);
			StudentInfo student = getItem(position);
			if (student.getGender().equals("male")) {
				icon.setImageResource(R.drawable.user_male);
			} else {
				icon.setImageResource(R.drawable.user_female);
			}
			TextView title = (TextView) convertView
					.findViewById(R.id.row_title);
			title.setText(student.getName());

			return convertView;
		}

	}

}
